<template>
  <DialogTable
    :title="title"
    v-model:show="open"
    v-model="currentData"
    :api="requestApi"
    :multiple="multiple"
    rowKey="code"
    :dataCallback="dataCallback"
    labelKey="name"
    :columns="columns"
    :search="searchParams"
    @change="submitForm"
  ></DialogTable>
</template>

<script setup name="MatDialog">
import { listType } from "@/api/base/equipment/equipmentTypeApi";
import DialogTable from "@/components/DialogTable";
const open = defineModel("show");

const currentData = ref([]);
const multiple = ref(true);
const title = ref("");
const props = defineProps({
  data: {
    type: [Array, Object],
    default: () => [],
  },
});
const { data: defaultData } = toRefs(props);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    equipNo: undefined,
    name: undefined,
    status: undefined,
  },
  columns: [
    {
      label: "设备类型编号",
      align: "center",
      prop: "code",
    },
    {
      label: "设备类型名称",
      align: "center",
      prop: "name",
    },
  ],
  searchParams: [
    {
      label: "设备类型名称",
      prop: "name",
    },
  ],
});

const requestApi = ref(listType);
watch(open, (newValue) => {
  if (newValue) {
    currentData.value = defaultData.value;
  }
});
const { columns, searchParams } = toRefs(data);
const dataCallback = (res) => {
  return res.rows || [];
};
const emit = defineEmits(["change"]);

function submitForm() {
  open.value = false;
  emit("change", currentData.value);
}
</script>

<style lang="scss" scoped></style>
